package cn.codenest.rabbitmqbootpublisher.callback;

import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * @author ：Hyman
 * @date ：Created in 2021/7/28 9:45
 * @description：
 * @modified By：
 * @version: $
 */
public class MyReturnCallback implements RabbitTemplate.ReturnsCallback {

    @Override
    public void returnedMessage(ReturnedMessage returnedMessage) {
        String str = String.format("消息发送失败-消息回退，应答码：%s，原因：%s，交换机：%s，路由键：%s",
                returnedMessage.getReplyCode(),
                returnedMessage.getReplyText(),
                returnedMessage.getExchange(),
                returnedMessage.getRoutingKey());
        System.out.println(str);
    }
}
